package com.freejava.usejpa.dao;

import org.springframework.data.jpa.repository.support.SimpleJpaRepository;

import javax.persistence.EntityManager;
import javax.persistence.Query;
import java.io.Serializable;
import java.util.List;

/**
 * 用于公共Jpa的接口实现类
 *
 * @param <T>
 * @param <ID>
 */
public class MyBaseJpaRepository<T, ID extends Serializable> extends SimpleJpaRepository<T, ID> implements BaseRepository<T, ID> {
    private final EntityManager entityManager;
    private Class<T> myclass;

    public MyBaseJpaRepository(Class<T> domainClass, EntityManager entityManager) {
        super(domainClass, entityManager);
        this.entityManager = entityManager;
        this.myclass = domainClass;
    }


    @Override
    public List sqlObjectList(String sql, Object obj) {
        Query query = entityManager.createNativeQuery(sql, obj.getClass());
        List list = query.getResultList();
        return list;
    }

    @Override
    public List<Object[]> sqlArrayList(String sql) {
        return null;
    }

    @Override
    public List sqlSingleList(String sql) {
        return null;
    }
}

